package handler

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"video-proj/internal/dto"
	"video-proj/internal/model"
	"video-proj/response"
)

func FindVideo(c *gin.Context) {

	var video model.Video
	err := c.ShouldBind(&video)
	if err != nil {
		response.Error(c, "解析失败")
		return
	}
	page, _ := strconv.Atoi("page")
	size, _ := strconv.Atoi("size")
	if page < 1 {
		page = 1
	}
	if size < 1 || size > 100 {
		size = 10
	}
	err = dto.FindVideo(&video, video.Title, page, size)
	if err != nil {
		response.Error(c, "查询失败")
		return
	} else {
		response.Success(c, "查询成功", video)
	}
}
